1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4 using
System;
5
6 public
class Finder {
7
8     
public static GameObject RayHitFromScreen(Vector3 hitPosition) {
9         Ray ray = Converter.ScreenPointToRay(hitPosition);
10         RaycastHit hit;
11         
if (Physics.Raycast(ray, out hit, float.PositiveInfinity, GameManager.Instance.CLickableMask)) {
12                     
return hit.transform.gameObject;
13         }
14
15         
return null;
16     }
17
18     
public static T RayHitFromScreen<T>(Vector3 hitPosition) {
19         GameObject go = RayHitFromScreen(hitPosition);
20         
if (go == null) return default(T);
21         
object o = go.GetComponent(typeof(T));
22         
if (o == null) return default(T);
23         
return (T) Convert.ChangeType(o,typeof(T));
24     }
25
26     
public static IClickable IClickableRayHitFromScreen(Vector3 hitPosition) {
27         Ray ray = Converter.ScreenPointToRay(hitPosition);
28         RaycastHit hit;
29         
if (Physics.Raycast(ray, out hit, float.PositiveInfinity, GameManager.Instance.CLickableMask)) {
30             
return hit.transform.gameObject.GetComponent(typeof(IClickable)) as IClickable;
31         }
32
33         
return null;
34     }
35
36 }


Gõ tìm kiếm nhanh...